﻿$(document).ready(function () {
    function changeinputerror(object, flag, errormsg) {
        if (flag) {
            if ($(object).parent('a.info').find('span').length == 0)
                $(object).after('<span style="color:red;">' + errormsg + '</span>');
        } else
            $(object).parent('a.info').find('span').remove();
    }


    $('input').focusout(function () {
        changeinputerror(this, this.value == '', '该项不能为空');
    });


    $('#UserName').focusout(function () {
        var reg = new RegExp('^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+$');
        changeinputerror(this, !reg.test(this.value), '邮箱格式不正确');
    });


    $('#ConfirmPassword').focusout(function () {
        changeinputerror(this, this.value != $('#Password').val(), '两次输入的密码不一致');
    });


    $('#SchoolYear').focusout(function () {
        var reg = new RegExp('^[0-9]{4}$');
        changeinputerror(this, !reg.test(this.value) || parseInt(this.value) < 1990 || parseInt(this.value) > 2011, '年份输入格式不正确');
    });
});